import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class L15R {
    public static void main(String[] args) {
        int[] nums = {0, 0, 0};
//        int[] nums = {-1, 0, 1, 2, -1, -4};

        List<List<Integer>> lists = new Solution().threeSum(nums);
        System.out.println(lists.toString());
    }

    static class Solution {
        public List<List<Integer>> threeSum(int[] nums) {
            Arrays.sort(nums);
            List<List<Integer>> list = new ArrayList<>();

            int i = 0;
            while (i <= nums.length - 3) {
                int left = i + 1;
                int right = nums.length - 1;

                if (i > 0 && nums[i] == nums[i - 1]) {
                    i++;
                    continue;
                }

                while (left < right) {
                    if (nums[i] + nums[left] + nums[right] > 0) {
                        right--;
                    } else if (nums[i] + nums[left] + nums[right] < 0) {
                        left++;
                    } else {
                        List<Integer> asList = Arrays.asList(nums[i], nums[left], nums[right]);
                        list.add(asList);
                        while (right > left && nums[right] == nums[right - 1]) right--;
                        while (right > left && nums[left] == nums[left + 1]) left++;

                        right--;
                        left++;
                    }
                }
                i++;
            }
            return list;
        }
    }
}
